<%-- 
    Document   : LoginPage
    Created on : 23.04.2011, 22:28:44
    Author     : ain
--%>

<%@page import="unc.pds.service.ServiceBeanRemote"%>
<%@page import="unc.pds.model.UserRemote"%>
<%@page import="unc.pds.service.LoginRemoteHome"%>
<%@page import="unc.pds.service.LoginRemote"%>
<%@page import="javax.naming.InitialContext"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Login</title>
    </head>
    <body>
<form action="LoginPage.jsp" >
            <input type="text" name="name" value="root">
            <input type="text" name="pass" value="toor">
            <input type="submit" name="login" value="login">
        </form>
        <%
        if (request.getParameter("name")!=null){
            LoginRemote LoginR = ((LoginRemoteHome)(new InitialContext()).lookup("ejb/Login")).create();
            ServiceBeanRemote sbr = LoginR.login(request.getParameter("name"), request.getParameter("pass"));
            UserRemote UR = sbr.getUser();
             session.setAttribute("user", UR);
            session.setAttribute("service", sbr);           
            response.sendRedirect("MainPage.jsp?id="+UR.getKey());
        }
        %>
    </body>
</html>
